
<script type='text/javascript'>
$(document).ready(function(){				
	$('textarea').elastic();
	autosave();


$('#opener').click(function() {
	$( "#dialog" ).dialog({ title: 'Szablony opisu', width: 600, height: 400 });
	return false;
});

$('#openerb').click(function() {
	$( "#dialogb" ).dialog({ title: 'Szablony opisu', width: 600, height: 400 });
	return false;
});

$('#openerc').click(function() {
	$( "#dialogc" ).dialog({ title: 'Szablony opisu', width: 600, height: 400 });
	return false;
});

$('#openerw').click(function() {
	$( "#dialogw" ).dialog({ title: 'Szablony opisu', width: 600, height: 400 });
	return false;
});

$('.szab_zal').click(function(){
	$('#wiz_zalecenia_opis').val($('#wiz_zalecenia_opis').val() + "\n"+$(this).text());
	$('textarea').elastic();
	$( "#dialog" ).dialog("close");
});

$('.szab_bad').click(function(){
	$('#wiz_badanie_opis').val($('#wiz_badanie_opis').val() + "\n"+$(this).text());
	$('textarea').elastic();
	$( "#dialogb" ).dialog("close");
});

<?php
if ($_SESSION['grupa_realiz_wiz']==3){
echo '$(".szab_badc").click(function(){
	$("#wiz_badanie_opis_bad").val($("#wiz_badanie_opis_bad").val() + "\n"+$(this).text());
	$("textarea").elastic();
	$( "#dialogc" ).dialog("close");
});	
';
}
else {
	echo '$(".szab_badc").click(function(){
	$("#wiz_badanie_opis").val($("#wiz_badanie_opis").val() + "\n"+$(this).text());
	$("textarea").elastic();
	$( "#dialogc" ).dialog("close");
});	
';
}

?>




$('.szab_wyw').click(function(){
	$('#wiz_wyw_opis').val($('#wiz_wyw_opis').val() + "\n"+$(this).text());
	$('textarea').elastic();
	$( "#dialogw" ).dialog("close");
});

$('.opis').keyup(function() {
  $( "#zmm_typw" ).hide();
});


$("#zap_butt").click(function(){
    var ile_znakow = 0;
    $('textarea').each(function() {
        ile_znakow += $(this).val().length;
    });
    
        if(ile_znakow > 2) {
            $("#fancy").validate();
            }
        else {
            $("#icd10").removeClass("required");
            }
     
    });
    
 $("#zap_anul").click(function(){
    $("#icd10").removeClass("required");
  });
$("#icd10").autocomplete('./check/check_icd10.php', { 
    width:800, 
    minChars:1,
    mustMatch: true ,
    formatItem: function(row, i, max) { 
        return " <b>" + row[1] + "</b>: " + row[2]; 
    }, 
    formatMatch: function(row, i, max) { 
        return row[1]; 
    }, 
    formatResult: function(row) { 
        return row[1];
    }
});

$("#icd10").result(function(event, data, formatted) {
	if (data)
		$("#status").html('<b>' + data[2] + '</b>');
		});




  });


<?php

if ($_POST['wyb_wiz_ed']){
foreach ($_POST['wyb_wiz_ed'] as $i => $w){
		$_SESSION['wyb_wiz_ed']=$i;
	}
}
	if ($_GET['realiz_wiz']) {
	$_SESSION['wyb_wiz_ed']=$_GET['realiz_wiz'];
	$_SESSION['config_pop']='wizyty_podglad';
	}

$sql="select wizyty.typ_wiz, sl_uslugi.id_grupy from wizyty, sl_uslugi where sl_uslugi.id = wizyty.typ_wiz and wizyty.id = ".$_SESSION['wyb_wiz_ed'];
#echo $sql;
$result=mysql_query($sql);
	$row = mysql_fetch_array($result);
	$_SESSION['typ_realiz_wiz']=$row[0];
	$_SESSION['grupa_realiz_wiz']=$row[1];



if ($_SESSION['grupa_realiz_wiz']==1){
	echo 'function autosave()
	{
		var t = setTimeout("autosave()", 20000);	
		var wiz_badanie_opis = $("#wiz_badanie_opis").val();
		var wiz_wyw_opis = $("#wiz_wyw_opis").val();
		var wiz_zalecenia_opis = $("#wiz_zalecenia_opis").val();
                var icd10 = $("#icd10").val();
		if (wiz_badanie_opis.length > 0 ||  wiz_wyw_opis.length > 0 || wiz_zalecenia_opis.length > 0)
		{
			$.ajax(
			{
				type: "POST",
				url: "autosave_wywiad.php",
				data: "article_id=" + '.$_SESSION['wyb_wiz_ed'].' + "&wiz_badanie_opis=" + wiz_badanie_opis + 
				"&wiz_wyw_opis=" + wiz_wyw_opis + 
				"&wiz_zalecenia_opis=" + wiz_zalecenia_opis +
                                "&icd10=" + icd10,
				cache: false,
				success: function(message)
				{	
					$("#timestamp").empty().append(message);
				}
			});
		}
	}';
}

elseif ($_SESSION['grupa_realiz_wiz']==2){
        
        

	echo 'function autosave()
	{
		var t = setTimeout("autosave()", 20000);	
		var wiz_badanie_opis = $("#wiz_badanie_opis").val();
                var icd10 = $("#icd10").val();
		if (wiz_badanie_opis.length > 0 )
		{
			$.ajax(
			{
				type: "POST",
				url: "autosave_badanie.php",
				data: "article_id=" + '.$_SESSION['wyb_wiz_ed'].' + "&wiz_badanie_opis=" + wiz_badanie_opis +
                                "&icd10=" + icd10,
				cache: false,
				success: function(message)
				{	
					$("#timestamp").empty().append(message);
				}
			});
		}
	}';
}
elseif ($_SESSION['grupa_realiz_wiz']==3){
	echo 'function autosave()
	{
		var t = setTimeout("autosave()", 20000);	
		var wiz_badanie_opis = $("#wiz_badanie_opis").val();
		var wiz_badanie_opis_bad = $("#wiz_badanie_opis_bad").val();
		var wiz_wyw_opis = $("#wiz_wyw_opis").val();
		var wiz_zalecenia_opis = $("#wiz_zalecenia_opis").val();
                var icd10 = $("#icd10").val();
		if (wiz_badanie_opis.length > 0 || wiz_badanie_opis_bad.length > 0 || wiz_wyw_opis.length > 0 || wiz_zalecenia_opis.length > 0)
		{
			$.ajax(
			{
				type: "POST",
				url: "autosave_badanieb.php",
				data: "article_id=" + '.$_SESSION['wyb_wiz_ed'].' + "&wiz_badanie_opis=" + wiz_badanie_opis + 
				"&wiz_badanie_opis_bad=" + wiz_badanie_opis_bad + "&wiz_wyw_opis=" + wiz_wyw_opis + 
				"&wiz_zalecenia_opis=" + wiz_zalecenia_opis  +
                                "&icd10=" + icd10,
				cache: false,
				success: function(message)
				{	
					$("#timestamp").empty().append(message);
				}
			});
		}
	}';
}
?>


</script>

<div class="wyw">
<div  id="dialogw" style="padding:20px; display:none">
<?php 
$a=w;
include('szablony.php');?>
</div>
</div>

<div class="bad">
<div  id="dialogb" style="padding:20px; display:none">
<?php 
$a=b;
include('szablony.php');?>
</div>
</div>

<div class="badc">
<div  id="dialogc" style="padding:20px; display:none">
<?php 
$a=c;
include('szablony.php');?>
</div>
</div>

<div class="zal">
<div  id="dialog" style="padding:20px; display:none">
<?php 
$a=z;
include('szablony.php');?>
</div>
</div>



<?php
if ($_SESSION['dod_szablon_b']=='' || $_SESSION['dod_szablon_b']) unset($_SESSION['wiz_skad']);

if ($_SESSION['wiz_wart']==''){
$sql="select * from wizyty_inf where id_wiz=".$_SESSION['wyb_wiz_ed'];
#echo $sql;
$result=mysql_query($sql);

$ile=mysql_num_rows($result);
if ($ile==0) {
$sql="insert into wizyty_inf values ('".$_SESSION['wyb_wiz_ed']."', '', '', '')";
mysql_query($sql);
$data['icd10']='';
$data['id_wizyty']=$_SESSION['wyb_wiz_ed'];
$db->query("select * from wizyty_inf_dod where id_wizyty = ".$_SESSION['wyb_wiz_ed']);
if($db->affected_rows == 0){
$db->insert("wizyty_inf_dod", $data);
}
}

while($row = mysql_fetch_array($result))
{
$_SESSION['wiz_badanie_opis']=$_SESSION['wiz_badanie_opis'].$row['badanie'];
$_SESSION['wiz_wyw_opis']=$_SESSION['wiz_wyw_opis'].$row['wywiad'];
$_SESSION['wiz_zalecenia_opis']=$_SESSION['wiz_zalecenia_opis'].$row['zalecenia'];  
$_SESSION['wiz_wart']=1;
$kod=$db->query_first("select icd10 from wizyty_inf_dod where id_wizyty=".$_SESSION['wyb_wiz_ed']);
$_SESSION['icd10']=$kod['icd10'];
}
}
#}


##

$stymul="SELECT stymulator FROM pac WHERE id=".$_SESSION['wyb_pac_id'];
    $czy_stym = $db->query_first($stymul);
    if ($czy_stym['stymulator'] <>''&& $_SESSION['uzytk']['id_grupy']=='1'){
        echo '<h2>&hearts; '.$czy_stym['stymulator'].'</h2>';
    }
    


echo '<form action="index.php" method=POST class="fancy" id="fancy">';
echo '<table align="center" width="90%">';
if ($_SESSION['uzytk']['id_grupy']=='0') $klasaicd='class="required"';
##poczatek tabeli
if ($_SESSION['grupa_realiz_wiz']==1){
    echo '<tr><td>ICD10:</td><td class="linia"><input type="text" name="icd10" '.$klasaicd.' size=5 id="icd10" value="'.$_SESSION['icd10'].'"><span id="status"></span></td></tr>';
    echo '<tr><td>Wywiad</td><td align="center" class="linia"><textarea id="wiz_wyw_opis" name="wiz_wyw_opis" rows="6" cols="100" class="opis">'.$_SESSION['wiz_wyw_opis'].'</textarea></td><td><button id="openerw" class="butt">Szablon</button></td></tr>';
    echo '<tr><td>Badanie</td><td align="center" class="linia"><textarea id="wiz_badanie_opis" name="wiz_badanie_opis" rows="6" cols="100" class="opis">'.$_SESSION['wiz_badanie_opis'].'</textarea></td><td><button id="openerb" class="butt">Szablon</button></td></tr>';
    echo '<tr><td>Zalecenia</td><td align="center" class="linia"><textarea id="wiz_zalecenia_opis" name="wiz_zalecenia_opis" rows="6" cols="100" class="opis">'.$_SESSION['wiz_zalecenia_opis'].'</textarea></td><td><button id="opener" class="butt">Szablon</button></td></tr>';
	echo '<div id="timestamp"></div>';




##koniec tabeli
}
elseif ($_SESSION['grupa_realiz_wiz']==2){
  echo '<tr><td>ICD10:</td><td class="linia"><input type="text" name="icd10" size=5 id="icd10" value="'.$_SESSION['icd10'].'"><span id="status"></span></td></tr>';
	    echo '<tr><td>Badanie '.get_name('sl_uslugi', $_SESSION['typ_realiz_wiz']).'</td><td align="center" class="linia"><textarea id="wiz_badanie_opis" name="wiz_badanie_opis" rows="6" cols="100" class="opis">'.$_SESSION['wiz_badanie_opis'].'</textarea></td><td><button id="openerc" class="butt">Szablon</button></td></tr>';
		echo '<div id="timestamp"></div>';
}

elseif ($_SESSION['grupa_realiz_wiz']==3){
		
$opis_bad=explode('###!!!', $_SESSION['wiz_badanie_opis']);
  echo '<tr><td>ICD10:</td><td class="linia"><input type="text" name="icd10" size=5 id="icd10" '.$klasaicd.' value="'.$_SESSION['icd10'].'"><span id="status"></span></td></tr>';
 echo '<tr><td>Wywiad</td><td align="center" class="linia"><textarea id="wiz_wyw_opis" name="wiz_wyw_opis" rows="6" cols="100" class="opis">'.$_SESSION['wiz_wyw_opis'].'</textarea></td><td><button id="openerw" class="butt">Szablon</button></td></tr>';
 echo '<tr><td>Badanie</td><td align="center" class="linia"><textarea id="wiz_badanie_opis" name="wiz_badanie_opis" rows="6" cols="100" class="opis">'.$opis_bad[0].'</textarea></td><td><button id="openerb" class="butt">Szablon</button></td></tr>';
 echo '<tr><td>Badanie '.get_name('sl_uslugi', $_SESSION['typ_realiz_wiz'], 'nazwa_opis').'</td><td align="center" class="linia"><textarea id="wiz_badanie_opis_bad" name="wiz_badanie_opis_bad" rows="6" cols="100" class="opis">'.$opis_bad[1].'</textarea></td><td><button id="openerc" class="butt">Szablon</button></td></tr>';
 echo '<tr><td>Zalecenia</td><td align="center" class="linia"><textarea id="wiz_zalecenia_opis" name="wiz_zalecenia_opis" rows="6" cols="100" class="opis">'.$_SESSION['wiz_zalecenia_opis'].'</textarea></td><td><button id="opener" class="butt">Szablon</button></td></tr>';
 echo '<div id="timestamp"></div>';		    


}

$sql11="select sl_uslugi.* from sl_uslugi, gab_bad where sl_uslugi.id = gab_bad.id_bad and gab_bad.id_gab = ".$_SESSION['wyb_gab']." and sl_uslugi.akt=1 order by sl_uslugi.nazwa, sl_uslugi.id_grupy";

$result11=mysql_query($sql11);
	while($row11 = mysql_fetch_array($result11))
	{
		$list_typ_wiz[$row11['id']]=$row11['nazwa'];
	}

echo '<tr><td colspan=3 align="center">';

echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit value="Anuluj" name="wiz_anuluj" class="butt4" id="zap_anul">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit value="Zapisz" name="wiz_zapisz_ed" class="butt" id="zap_butt"></td></tr>';

echo '</form>';
echo '<tr><td colspan=3 align="center">';
echo '<div id="zmm_typw">Zmień typ wizyty na:';
echo '<form action="index.php" method=post>';
form_auto_submit_2m("zm_typ_wiz", $list_typ_wiz, $_SESSION['typ_realiz_wiz']);
echo '<input type=submit value="Zmień" name="wiz_zmien_typ" class="butt">';
echo '</div>';
echo '</form>';
echo '</td></tr>';
echo '</table>';



?>